package com.xxx.obj;

import java.io.*;

/**
 * @version v1.0
 * @Description:
 * @Author zhanzhongxin
 * @Date 2021/7/23 9:52
 * @Copyright 博为峰
 */
public class ObjectStreamDemo {
    public static void main(String[] args) throws IOException, ClassNotFoundException {
//        write();
        read();

    }

    private static void read() throws IOException, ClassNotFoundException {
        ObjectInputStream objectInputStream = new ObjectInputStream(new FileInputStream("./IO/obj.txt"));
        Student student = (Student) objectInputStream.readObject();
        System.out.println("student = " + student);
        System.out.println(student.sex);
    }

    public static void write() throws IOException {
        ObjectOutputStream objectOutputStream = new ObjectOutputStream(new FileOutputStream("./IO/obj.txt"));
        Student student = new Student("张三", 20);
        student.sex = "男";
        objectOutputStream.writeObject(student);
    }
}
